<?php 
/**
 * 道具静态板块
 */
class App_prop{
	/**
	 * 道具写入
	 * @param $name
	 * @param $type
	 * @param $harm
	 * @param $introduce
	 * @param $game
	 */
	public static function getAddProp($name , $price , $type , $harm , $introduce , $game , $uin){
		$Db = loadDB();
		$time = time();
		//把数据写入数组
		$insert_date = array(
			'name' => $name,
			'price' => $price,
			'type' => $type,
			'harm' => $harm,
			'introduce' => $introduce,
			'time' => $time,
			'uin' => $uin,
		);
		$success = $Db->doInsert($game , $insert_date);
		return $success ? 0 : 796;
	
	}
	/**
	 * 道具查询
	 */
	public static function getAllProp($game){
		$Db = loadDB();
		$result = $Db->getAll("SELECT * FROM {$game}");
		
		return $result;
	}
	/**
	 * 详细道具查询
	 */
	public static function getOneProp($game , $id){
		$Db = loadDB();
		$result = $Db->getOne("SELECT * FROM {$game} WHERE `id` = {$id}");
		
		return $result;
	}
	/**
	 * 修改道具
	 * @param unknown_type $uin
	 * @param unknown_type $lv
	 */
	public static function getAlterGameProp($id , $name , $price , $type , $harm , $introduce , $game , $uin){
		$Db=loadDB();
		$time = isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time();
		$update_data = array(
			'name' => $name,
			'price' => $price,
			'type' => $type,
			'harm' => $harm,
			'introduce' => $introduce,
			'time' => $time,
			'uin' => $uin,
		);
		$success = $Db->doUpdate($game , $update_data , '`id`= '.$id);
		return $success ? 0 : 794;
	}
	/**
	 * 道具类型对照
	 * @param $level
	 */
	public static function getGameProp($game) {
		$type = array();
		
		switch ($game) {
			case 'app_kingdoms_prop' : $type = array(
					'hp' => '疗伤',
					'ap' => '攻击',
					'steal' => '盗窃',
					'guard' => '防盗',
					'diligent' => '勤奋',
					'special' => '特殊',
					); break;
			case 'app_factory_prop' : $type = array(
					'hp' => '体力',
					); break;
			case 'app_showhand_prop' : $type = array(
					'perspective' => '穿透',
					'dormant' => '隐身',
					'random' => '随机',
					); break;
			case 'app_mora_prop' : $type = array(
					'repeat' => '重开',
					);break;
			case 'app_21_prop' : $type = array(
					'repeat' => '重开',
					);break;
		}
		return $type;
	}
	/**
	 * 查询个人的道具
	 * @param $uin
	 */
	public static function getAllOneselfProp($oneself_prop , $game , $uin){
		$Db = loadDB();
		
		$result = $Db->getAll("SELECT * FROM {$oneself_prop},{$game} WHERE {$oneself_prop}.uin = {$uin} AND {$oneself_prop}.prop_id = {$game}.id");
	
		return $result;
	} 
	/**
	 * 查询个人详细的道具
	 * @param $id
	 * @param $uin
	 */
	public static function getOneselfProp($oneself_prop , $uin , $id){
		$Db = loadDB();
		
		$result = $Db->getOne("SELECT * FROM {$oneself_prop} WHERE `uin` = {$uin} AND `prop_id` = {$id}");

		return $result;
	} 
	/**
	 * 个人道具写入 
	 * @param $id
	 * @param $uin
	 * @param $count
	 */
	public static function getAddOneselfProp($oneself_prop , $uin , $id , $count){
		$Db = loadDB();
		$time =time();
		$query_data = array(
			'uin' => $uin,
			'prop_id' => $id,
			'count' => $count,
			'time' => $time,
		);
		$success = $Db->doInsert($oneself_prop , $query_data);
		return $success ? 0 : 547;
	}
	/**
	 * 个人道具修改
	 * @param $id
	 * @param $uin
	 * @param $count
	 * @param $time
	 */
	public static function getAlterOneselfProp($oneself_prop , $id , $uin , $count , $time){
		$Db=loadDB();
		
		$update_data = array(
			'count' => $count,
			'time' => $time,
		);
		$success = $Db->doUpdate($oneself_prop , $update_data , '`uin`= '.$uin.' AND `prop_id` = ' . $id);

		return $success ? 0 : 548;
	}
	/**
	 * 删除道具
	 * @param unknown_type $uin
	 * @param unknown_type $id
	 */
	public static function delProp($oneself_prop , $uin , $id) {
		$Db = loadDB();
		
		$success = $Db->query("DELETE FROM {$oneself_prop} WHERE `uin` = {$uin} AND `prop_id` = {$id}");
		
		return $success ? 0 : 549;
	}
}
#end of script